<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title>{:getenv('APP_NAME')}后台系统</title>
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <link rel="shortcut icon" href="__IMG__favicon.ico">
    {load href="__CSS__bootstrap.min.css"}
    {load href="__CSS__font-awesome.min.css"}
    {load href="__CSS__animate.min.css"}
    {load href="__CSS__style.min.css"} 
</head>

<body class="fixed-sidebar full-height-layout gray-bg" style="overflow:hidden">
    <div id="wrapper">
        <!--左侧导航开始-->
        <nav class="navbar-default navbar-static-side" role="navigation">
            <div class="nav-close"><i class="fa fa-times-circle"></i>
            </div>
            <div class="sidebar-collapse">
                <ul class="nav" id="side-menu">
                    <li class="nav-header" style="text-align: center;">
                        <span><img alt="image" class="img-circle" src="__IMG__avatar.jpg" /></span>
                        <div class="dropdown profile-element">
                            <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                                <span class="block m-t-xs" style="margin:20px 0px 0px 0px"><h3><strong class="font-bold">{$admin.name}</strong></h3></span>
                            </a>
                            
                        </div>
                        <div class="logo-element"><i class="fa fa-home"></i>
                        </div>
                    </li>
 
{php}
$isDev = getenv('APP_DEBUG');
$data=db('category')->where(['tid' => 0, 'hideleft' => 1, 'id'=>['in', $adminTypeData]])->order('des desc,id asc')->cache('admincate1'.$admin['id'],60, 'admincategory')->select();
foreach($data as $k=>$v){   
{/php}
<li class="nav-item">
{php}
$url='';
if($v['controller'] && $v['function']){
    $url='class="J_menuItem" href="'.url($v['controller'].'/'.$v['function']).'"';
}else{
    $url='href="#"';
}
{/php}
    <a {$url}>
        <i class="fa fa-{$v.icon}"></i>
        <span class="nav-label">{$v.title}</span>
        {php}
        $data2=db('category')->where(['tid'=>$v['id'],'hideleft'=>1, 'id'=>['in', $adminTypeData]])->order('des desc,id asc')->cache('admincate2'.$admin['id'] .':' . $v['id'],60, 'admincategory')->select();
        if($data2){echo '<span class="fa arrow"></span>';}
        {/php}
    </a>
    {php}
    if($data2){
    {/php}
    <ul class="nav nav-second-level">
        {php}
        foreach($data2 as $k2=>$v2){
        {/php}

{php}
$url='';
if($v2['controller'] && $v2['function'] && ($admin['type'] == 1 or in_array($v2['id'], $adminTypeData))){
    if (!$isDev && !class_exists('\\app\\admin\\controller\\'.ucfirst($v2['controller'])) || !method_exists('\\app\\admin\\controller\\'.ucfirst($v2['controller']), $v2['function'])){
        continue;
    }
    $url='class="J_menuItem" href="'.url($v2['controller'].'/'.$v2['function']).'?'.$v2['get'].'"';
}else if(!$v2['controller'] && !$v2['function']){
    $url='class=""';
}else{
    $url='';
}
$data3=db('category')->where(['tid'=>$v2['id'],'hideleft'=>1, 'id'=>['in', $adminTypeData]])->order('des asc,id asc')->select();
{/php}
        {if condition = '($url or $admin.type == 1)'}
            <li><a {$url} id="menu{$v2.id}">{$v2.title}{php}if($data3){echo '<span class="fa arrow"></span>';}{/php}</a>
                {php}if($data3){{/php}
                <ul class="nav nav-third-level">
                    {php}
                    foreach($data3 as $k3=>$v3){
    if (!$isDev && !method_exists('\\app\\admin\\controller\\'.ucfirst($v3['controller']), $v3['function'])){
        continue;
    }
                    {/php}
                    <li>
                        <a class="J_menuItem" id="menu{$v3.id}"  href="{:url($v3['controller'].'/'.$v3['function'])}">{$v3.title}{$v3.get}</a>
                    </li>
                    {php}}{/php}
                </ul>
                {php}}{/php}
            </li>
        {/if}
        {php}}{/php}
    </ul>
    {php}}{/php}
</li>
{php}}{/php}

                </ul>
            </div>
        </nav>
        <!--左侧导航结束-->
        <!--右侧部分开始-->
        {load href="__JS__jquery.min.js"}
        <div id="page-wrapper" class="gray-bg dashbard-1">
            <div class="row border-bottom">
                <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                    <div class="navbar-header"><a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
                      <!--   <form role="search" class="navbar-form-custom" method="post" action="http://www.zi-han.net/theme/hplus/search_results.html">
                            <div class="form-group">
                                <input type="text" placeholder="请输入您需要查找的内容 …" class="form-control" name="top-search" id="top-search">
                            </div>
                        </form> -->
                    <div class="dbxiang">
                        <div>待审核：</div>
                        <div id="dtdsh">动态（<span></span>）</div>
                        <div id="pldsh">评论（<span></span>）</div>
                        <div id="xcdsh">相册（<span></span>）</div>
                        <div id="xxdsh">信息（<span></span>）</div>
                        <div id="zhdsh">招呼语（<span></span>）</div>
                        <div id="zldsh">资料（<span></span>）</div>
                        <div id="rzdsh">认证（<span></span>）</div>
                        <div id="cyydsh">常用语（<span></span>）</div>
                        <div id="bddsh">绑定（<span></span>）</div>
                         <div id="fatal_warn">致命预警（<span></span>）</div>
                    </div>

                    <script>
                        function getNeedToDo() {
                            $.get("{:url('admin/Index/getdsh')}?time=" + new Date().getTime(), function(data) {
                                // 解析服务器返回的逗号分隔字符串
                                const counts = data.split(',');

                                // 更新各个待审核项目的数量
                                $('#dtdsh span').text(counts[0] || '0');  // 动态待审
                                $('#pldsh span').text(counts[1] || '0');  // 评论待审
                                $('#xcdsh span').text(counts[2] || '0');  // 相册待审
                                $('#xxdsh span').text(counts[3] || '0');  // 信息待审
                                $('#zhdsh span').text(counts[4] || '0');  // 招呼语待审
                                $('#zldsh span').text(counts[5] || '0');  // 资料待审
                                $('#rzdsh span').text(counts[6] || '0');  // 认证待审（新增）
                                $('#cyydsh span').text(counts[7] || '0');  // 常用语待审
                                $('#bddsh span').text(counts[8] || '0');  // 绑定待审
                                $('#fatal_warn span').text(counts[9] || '0');  // 绑定待审
                    

                                // 处理数值颜色
                                updateSpanColors();
                            }).fail(function() {
                                // 错误处理
                                console.error('获取待审核数据失败');
                            });
                            setTimeout(getNeedToDo, 120000); // 30s后再次执行
                        }

                        // 更新span颜色的函数
                        function updateSpanColors() {
                            // 获取所有需要处理的span元素
                            $('div[id$="dsh"] span').each(function() {
                                const $span = $(this);
                                const value = parseInt($span.text().trim(), 10);

                                // 清除可能存在的样式
                                $span.removeClass('red-count');

                                // 如果数值大于0，添加红色样式
                                if (!isNaN(value) && value > 0) {
                                    $span.addClass('red-count');
                                }
                            });
                        }

                        // 页面加载完成后启动定时任务
                        $(function() {
                            // 初始加载时调用一次颜色处理
                            updateSpanColors();
                            getNeedToDo();
                        });
                    </script>

                    <style>
                        .dbxiang{
                            width: 100%;
                            height: 49px;
                            line-height: 58px;
                            font-size:14px;
                            margin-left:50px;
                        }
                        .dbxiang div{
                            display: inline-block;
                            font-size: inherit;
                            margin-left:5px;
                        }

                        /* 添加红色计数样式 */
                        .red-count {
                            color: red;
                            font-weight: bold; /* 可选：增加字体粗细以增强视觉效果 */
                        }
                    </style>
                    </div>
                    <ul class="nav navbar-top-links navbar-right">
                        {if condition="isset($kefu)"}
                        <li class="">
                            <a href="/chat" class="J_menuItem">在线客服IM</a>
                        </li>
                        {/if}
                        <li class="">
                            <a href="" class="J_menuItem unAudioPlay">语音播报已开启</a>
                        </li>
                        {eq name='admin.type' value='1'}
                        <li class="">
                            <a href="" class="J_menuItem dataclear">数据清理</a>
                        </li>
                        {/eq}
                        <li class="hidden-xs">
                            <a href="" class="J_menuItem cache">清空缓存</a>
                        </li>
                    </ul>
                </nav>
            </div>
            <div class="row content-tabs">
                <button class="roll-nav roll-left J_tabLeft"><i class="fa fa-backward"></i>
                </button>
                <nav class="page-tabs J_menuTabs">
                    <div class="page-tabs-content">
                        <a href="javascript:;" class="active J_menuTab" data-id="{:url('main')}">首页</a>
                    </div>
                </nav>
                <button class="roll-nav roll-right J_tabRight"><i class="fa fa-forward"></i>
                </button>
                <div class="btn-group roll-nav roll-right">
                    <button class="dropdown J_tabClose" data-toggle="dropdown">关闭操作<span class="caret"></span>

                    </button>
                    <ul role="menu" class="dropdown-menu dropdown-menu-right">
                        <li class="J_tabShowActive"><a>定位当前选项卡</a>
                        </li>
                        <li class="divider"></li>
                        <li class="J_tabCloseAll"><a>关闭全部选项卡</a>
                        </li>
                        <li class="J_tabCloseOther"><a>关闭其他选项卡</a>
                        </li>
                    </ul>
                </div>
                <a href="{:url('index/out')}" class="roll-nav roll-right J_tabExit"><i class="fa fa fa-sign-out"></i> 退出</a>
            </div>
            <div class="row J_mainContent" id="content-main">
                <iframe class="J_iframe" name="iframe0" width="100%" height="100%" src="{:url('main')}" frameborder="0" data-id="{:url('main')}" seamless></iframe>
            </div>
            {if condition="$icp"}
            <div class="footer">
                <div class="pull-right"> 
                <!-- Copyright &copy; 2013-2018 <a href="http://www.xxx.cn/" target="_blank">XXX网络</a> 版权所有 <a href="http://www.xxx.cn/" target="_blank">技术支持</a> -->
                {$icp}
                </div>
            </div>
            {else/}
            <style>
                #content-main {
                    height: calc(100% - 100px);
                }
            </style>
            {/if}
        </div>
        <!--右侧部分结束-->
        <!--<div id="small-chat">
            <span class="badge badge-warning pull-right">5</span>
            <a class="open-small-chat">
                <i class="fa fa-comments"></i>
            </a>
        </div>-->
    </div>
    {load href="__JS__jquery.min.js"}
    {load href="__JS__bootstrap.min.js"}
    {load href="__PLUGINS__metisMenu/jquery.metisMenu.js"}
    {load href="__PLUGINS__slimscroll/jquery.slimscroll.min.js"}
    {load href="__PLUGINS__layer/layer.js"}
    {load href="__JS__hplus.min.js"}
    {load href="__JS__contabs.min.js"}
    {load href="__PLUGINS__pace/pace.min.js"}
    {load href="__PLUGINS__sweetalert/sweetalert.css"}
    {load href="__PLUGINS__sweetalert/sweetalert.min.js"}
    {load href="__PLUGINS__toastr/toastr.min.css"}
    {load href="__PLUGINS__toastr/toastr.min.js"}
    <script type="text/javascript">

    $('.cache').click(function(){
        var layerindex = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
        $.getJSON("{:url('cache_del')}",function(result){
            $.each(result, function(i, name){
              swal(name);
            });
            layer.close(layerindex);
        });
    })

    $('.zhuan').click(function () {
        var layerindex = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
        $.getJSON("{:url('jinbi')}", function (result) {
            $.each(result, function (i, name) {
                swal(name);
            });
            layer.close(layerindex);
        });
    })
    $('.dataclear').click(function(){
        layer.open({
          content: '请选择您要清理的聊天数据。注意：单次仅清理两万条'
          ,btn: ['提醒', '重复1', '重复2', '7天前']
          ,btn1: function(index, layero){
            var layerindex = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
            $.getJSON("{:url('usertalk/rmchats', ['type'=>1])}", function (result) {
                console.log(result)
                $.each(result, function (i, name) {
                    swal(name);
                });
                layer.close(layerindex);
            });
            return false;
          }
          ,btn2: function(index, layero){
            var layerindex = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
            $.getJSON("{:url('usertalk/rmchats', ['type'=>2])}", function (result) {
                console.log(result)
                $.each(result, function (i, name) {
                    swal(name);
                });
                layer.close(layerindex);
            });
            return false;
          }
          ,btn3: function(index, layero){
            var layerindex = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
            $.getJSON("{:url('usertalk/rmchats', ['type'=>3])}", function (result) {
                console.log(result)
                $.each(result, function (i, name) {
                    swal(name);
                });
                layer.close(layerindex);
            });
            return false;
          }
          ,btn4: function(index, layero){
            var layerindex = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
            $.getJSON("{:url('usertalk/rmchats', ['type'=>4])}", function (result) {
                console.log(result)
                $.each(result, function (i, name) {
                    swal(name);
                });
                layer.close(layerindex);
            });
            return false;
          }
        });
    })
    <?php if (!$isDev) { ?>
    window.onload = () => {
        let navs = $(".nav-item ul")
        for (var i = navs.length - 1; i >= 0; i--) {
            if ($(navs[i]).children().length == 0) {
                $(navs[i]).parent().remove()
            }
        }
    }
    <?php } ?>
    </script>

    <script>
    var audioTipPlay = true

    function setAudioTipPlayText(state) {
        if (state) {
            console.log(state);
            $('.unAudioPlay').text('语音播报已开启')
        } else {
            $('.unAudioPlay').text('语音播报已关闭')
        }
    }
    window.onload = function () {
        initaudioTipPlay()
        auditTip()
        // setInterval(()=>{
        //     auditTip()
        // }, 5000)
        <?php if (isset($kefu)) { ?>
            let kefu = JSON.parse('{:json_encode($kefu)}')
            console.log(kefu)
            var storage = window.sessionStorage;

            storage.setItem('kefu_token', kefu.token);
            storage.setItem('admin', kefu.id);
        <?php } ?>
        
    }

    $('.unAudioPlay').click(function() {
        audioTipPlay = !audioTipPlay
        window.localStorage.setItem('audioTipPlay', audioTipPlay)
        setAudioTipPlayText(audioTipPlay)
    })

    function initaudioTipPlay() {
        let state = window.localStorage.getItem('audioTipPlay')
        state = state == 'true' ? true : false
        audioTipPlay = state
        setAudioTipPlayText(state)
    }

    var audio

    function notification(content, mid, audioPath) {
        // 自定义 HTML 内容
        var customHtml = `
            <div>
                <p>${content}</p>
                <a href="#" class="btn-check" data-mid="${mid}">去查看</a>
            </div>
        `;

        if (audioTipPlay) {
            audio = new Audio(audioPath); // 替换为你的音频文件路径
        }

        // 设置 Toastr 选项
        toastr.options = {
            "closeButton": true, // 显示关闭按钮
            "positionClass": "toast-bottom-right", // 设置位置为右下角
            "timeOut": "0", // 不自动关闭
            "onShown": function () {
                audio && audio.play();
                // 绑定按钮点击事件
                $('.btn-check').off().on('click', function(e) {
                    e.preventDefault(); // 防止默认行为
                    // 执行点击后的操作，例如跳转到特定页面
                    let mid = $(this).data('mid')
                    // alert('您点击了“去查看”按钮！'+`#menu${mid}`);
                    $(`#menu${mid}`).click()
                    // 或者使用 window.location.href = 'http://example.com';
                });
            }
        };

        // 显示自定义内容的通知
        toastr.info(customHtml);
    }
        
    function auditTip() {
        $.getJSON("{:url('auditTip')}", function (result) {
            console.log(result.ret)

            if (result.ret.length > 0) {
                result.ret.forEach(item => {
                    notification(`您有新的 ${item.name} 待处理`, item.menuid, item.audio);
                })
            }
        });
    }
    
    </script>

</body>
</html>
